package sharewithus.advice;

import javax.jms.Queue;

import org.apache.activemq.command.ActiveMQQueue;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;

import sharewithus.business.dto.UserIntegralDTO;
import framelib.common.SessionData;
import framelib.utils.DateUtil;
import framelib.utils.ThreadLocalUtil;


/**
 * Title:UserIntegral
 * Description:
 * @Create_by:Vince Yu
 * @Create_date:2012-5-25
 * @Last_Edit_By:
 * @Edit_Description
 * @version:ShareWithUs 1.0
 * 
 */
@Aspect
public class UserIntegral {

	@Autowired
	@Qualifier("jmsTemplate")
	private JmsTemplate jmsTemplate;
	
	@Pointcut("execution(* checkPassword*(..))")
	private void allSaveMethod(){};

	
	@After("allSaveMethod()")
	public void checkUser() throws Throwable{
		// 连接点对象的方法
		//Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
		// 连接点方法方法名  
        //String methodName = method.getName();
		//Object target = proceedingJoinPoint.getTarget();   
		//Object[] args = proceedingJoinPoint.getArgs();
		//Class<?>[] parameterTypes = method.getParameterTypes();
		//获取目标方法  
        //method = target.getClass().getMethod(methodName, parameterTypes);
		StringBuffer sbf = new StringBuffer();
		UserIntegralDTO bean = new UserIntegralDTO();
		
		SessionData sd = ThreadLocalUtil.getSessionData();
		
		bean.setDescription(DateUtil.getSystemTime("date") + "登录积分奖励");
		bean.setExpennd(0);
		bean.setFlag(1);
		bean.setIncome(5);
		bean.setRemarks("");
		bean.setTakeTime(DateUtil.getSystemTime().toString());
		bean.setType(1);
		bean.setUserId(sd.getId());
		//Object returnValue = proceedingJoinPoint.proceed();
		// 发送
		Queue queue = new ActiveMQQueue("userIntegral");
		jmsTemplate.setDefaultDestination(queue);
		jmsTemplate.convertAndSend(bean);
	}

	/**
	 * 2011-5-18, 下午06:53:49 方法描述：判断参数是否是java中的类型
	 * 
	 * @param clz
	 * @return
	 */
	public static boolean isJavaClass(Class<?> clz) {
		return clz != null && clz.getClassLoader() == null;
	}

}
